<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="地层压力 或 关井油压 (MPa)" prop="dcyl">
				<u-input :border="border" placeholder="地层压力 或 关井油压" v-model="model.dcyl" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="液柱的垂直高度 (m)" prop="yzcg">
				<u-input :border="border" placeholder="液柱的垂直高度" v-model="model.yzcg" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="钻井液密度安全系数 (g/cm³)" prop="zjjmd">
				<u-input :border="border" placeholder="钻井液密度安全系数 " v-model="model.zjjmd" type="number"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}"
					label-width="300" :label-position="labelPosition" label="地层压力的值为：" prop="diFaLan">
					<span v-if="model.yjymd"> {{model.yjymd}} g/cm3 </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">ρ压 = Px /（gH）+ ρsf</view>
				<view class="u-item-desc">
				式中：<br>
				ρ压 —压井液密度，g/cm3；<br>
				Px  —地层压力或关井油压，MPa；<br>
				g—重力，9.81N/kg；<br>
				ρSf—钻井液密度安全系数（一般油层取0.05-0.1g/cm3，气层取0.07-0.15g/cm3）；<br>
				H—液柱的垂直高度，m。<br>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					dcyl: '',
					yzcg: '',
					zjjmd: '',
					yjymd: ''
				},
				rules: {
					dcyl: [{
						required: true,
						message: '请填写地层压力 或 关井油压',
						trigger: 'blur'
					}],
					yzcg: [{
						required: true,
						message: '请填写液柱的垂直高度',
						trigger: 'blur'
					}],
					zjjmd: [{
						required: true,
						message: '请填写钻井液密度安全系数',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
							
							const ρ = parseFloat(this.model.dcyl);
							const H = parseFloat(this.model.yzcg);
							const g = 9.81; // 重力加速度，m/s²
							const psf=parseFloat(this.model.zjjmd);
							
							 // Px /（gH）+ ρsf
							// Pl = 10⁻³ × ρ × g × H + Pm
							this.model.yjymd = (ρ / (g*H) +psf).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>